function trim(val)
{
	 return val.replace(/(^\s*)|(\s*$)/g, "");
}

function updateOneInfo(num,info_id,pub_date) { 
		document.getElementById('updateThisInfo'+num).innerHTML = '<img src="/program/admin/images/wait.gif"/>';
		jQuery.ajax( {
			   type: 'POST',
			   url: 'updateOneInfo.jsp',
			   data: 'info_id='+info_id+'&pub_date='+pub_date+'&num='+num,
			   success: function(msg){
					document.getElementById('updateThisInfo'+num).innerHTML=msg;
				 }
			}); 
	}
function isMaxLen(o)
{
	 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";
	 if(o.getAttribute && o.value.length>nMaxLen)
	 {
	 	  o.value=o.value.substring(0,nMaxLen);
	 }
}



function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}

function judgeCheck()
{
    var pkid_string = '';
		var listsize = document.getElementById('listsize').value;
		for(var i=0;i<listsize;i++)
		{
				if(document.getElementById('checkone'+i).checked)
				{
					pkid_string += document.getElementById('checkone'+i).value+'|';
				}
		}
    return pkid_string;
}

//var one_member_price ='';

function ChangeAreaStyle(){
	document.getElementById("area_attr").value = '';
	document.getElementById("areaId1").style.display = 'none';
	document.getElementById("areaId2").style.display = 'block';
}



function changeTime(){

	var obj = document.getElementById('up_operating').value;
	if( obj == '' || obj.indexOf('-')>-1 || obj.indexOf('c')>-1 || obj.indexOf('d')>-1 ){
		document.getElementById('b_g').style.display = 'none';
	}else{
		document.getElementById('b_g').style.display = 'inline';
	}
}

function operateInfo(val){

	var oper = document.getElementById(val+'_operating').value;
	if(oper == ''){
		alert('请选择操作方式!');
		return false;
	}

	var listsize = document.getElementById('listsize').value;

	var pkid_string = judgeCheck();
	if( pkid_string == '' ){
		alert('请至少选择一条商品进行操作!');
		return false;
	}
	if( oper == '-' ){
		document.getElementById('pkid').value = pkid_string;
		document.indexForm.action = '/doTradeReg.do';
		document.getElementById('bpm_id').value = '9858';
		if(window.confirm('确认删除吗?')){
			document.indexForm.submit();
		}
 	} else if( 'abcd'.indexOf(oper) > -1 ) {
		document.getElementById('pkid').value = pkid_string;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '8333';
		if(window.confirm('确认提交吗?')){
			document.indexForm.submit();
		}
	} else {
		document.getElementById('pkid').value = pkid_string;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '2491';
		if(window.confirm('确认提交吗?')){
			document.indexForm.submit();
		}
	}

}

function deleteOneInfo(pkid,bpm_id)
{

	if(window.confirm('确认删除吗？'))
	{
	  window.location.href='/doTradeReg.do?pkid='+pkid+'&bpm_id='+bpm_id;
 	}
}




function subForm(){

	//------  biz attr validate
	var attrSize = document.getElementById('attrsize').value;
	var attr_value = '';
	for( var j = 0; j < attrSize; j++ )
	{
		var item;
		var attrStr ='';
		var attrId = document.getElementById('attr_id'+j).value;
		var attrName = document.getElementById('attr_name'+j).value;
		var conType = document.getElementById('con_type' + j).value;
		var defaultTag = document.getElementById('default_tag' + j).value;

		// select
		if(conType == '0'){
		  attrStr= document.getElementById('attr_value'+j).value;
			if( attrStr == '' && defaultTag == '0'){
				alert('请选择' + attrName + '！'  );
				return;
			}
		}

		// input
		if(conType == '1'){
				attrStr = document.getElementById('attr_value'+j).value;
				if( attrStr == '' && defaultTag == '0'){
					alert('请输入' + attrName+'！');
					//document.getElementById('attr_id'+j).focus();
					return;
				}
		}

		//chechbox
		if( conType == '2'){
			var valueSize = document.getElementById('valuesize'+j).value;
			for( var r = 0; r < valueSize; r++ ){
				 if( document.getElementById('attr_value'+j+'_'+r).checked){
					attrStr +=  document.getElementById('attr_value'+j+'_'+r).value + '|';
				 }
			}
			if( attrStr == '' && defaultTag=='0'){
				alert('请选择' + attrName+'！' );
				return;
			}
		}
		if(attrStr != ''){
			item = attrId+"|"+attrStr;
			attr_value += item +',';
		}
	}

	document.getElementById('attr_desc').value = attr_value;

	if(trim(document.getElementById('title').value)==''){
	  alert('请输入产品标题！');
	  return;
	}
	var str = CKEDITOR.instances.product_desc.getData();
	str = trim(str);
	if(str == ''){
		alert('请输入详细说明!');
		CKEDITOR.instances.product_desc.focus();
		return;
	}
    
/*f(document.getElementById('province').value!=''){
		var area_attr_str = '';
		area_attr_str += document.getElementById('province').value+'|';
		if(document.getElementById('eparchy_code').value!=''){
			area_attr_str += document.getElementById('eparchy_code').value+'|';
			if(document.getElementById('city_code').value!=''){
				area_attr_str += document.getElementById('city_code').value+'|';
			}
		}
		if(area_attr_str == ''){
			alert('请选择工作地区！');
			return;
		}
		document.getElementById('area_attr').value = area_attr_str;
	}
	*/
	document.addForm.submit();

}

function searchForm(){

	document.indexForm.submit();

}

function setProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('province');
		DWRUtil.addOptions('province',{'':'请选择'});
		DWRUtil.addOptions('province',data);
	})
}
function setCitys(prov)
{
   var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions('eparchy_code');
		DWRUtil.addOptions('eparchy_code',{'':'请选择'});
		DWRUtil.addOptions('eparchy_code',data);
		DWRUtil.removeAllOptions('city_code');
		DWRUtil.addOptions('city_code',{'':'请选择'});
	});
}

function setAreas(city_id){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions('city_code');
		DWRUtil.addOptions('city_code',{'':'请选择'});
	 	DWRUtil.addOptions('city_code',data);
	});
}